/*
 * (c) Copyright 2002 HMS.
 * All Rights Reserved.
 */
package com.bff.mpd.musicjukebox.ui.components;

import com.bff.mpd.musicjukebox.lib.ColorProperties;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JTable;

/**
 * @author bill
 */
public class SongTable extends JTable {

    public SongTable() {
        this(new SongTableModel());
    }

    public SongTable(SongTableModel tm) {
        super(tm, null, null);
        setDefaultRenderer(Object.class, new SongCellRenderer());
        setFillsViewportHeight(true);
        setGridColor(ColorProperties.TABLE_HEADER_BACKGROUND);
        setIntercellSpacing(new Dimension(1, 1));
        setShowGrid(false);
        setShowVerticalLines(true);
    }

    /**
     * Paints empty rows too, after letting the UI delegate do
     * its painting.
     
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        paintEmptyRows(g);
    }

    /**
     * Paints the backgrounds of the implied empty rows when the
     * table model is insufficient to fill all the visible area
     * available to us. We don't involve cell renderers, because
     * we have no data.
     
    protected void paintEmptyRows(Graphics g) {
        final int rowCount = getRowCount();
        final Rectangle clip = g.getClipBounds();
        int columnCount = columnModel.getColumnCount();
        if (rowCount * rowHeight < clip.height) {
            for (int i = rowCount; i <= clip.height / rowHeight; ++i) {
                g.setColor(colorForRow(i));
                g.fillRect(clip.x, i * rowHeight, clip.width, rowHeight);
            }
        }
    }
     */

    /**
     * Returns the appropriate background color for the given row.
     */
    protected Color colorForRow(int row) {
        return (row % 2 == 0) ? ColorProperties.LIST_BACKGROUND_EVEN : ColorProperties.LIST_BACKGROUND_ODD;
    }
}
